
/**
 * 
 */
package com.zsrt.day20170412.student.client;


import java.util.Scanner;

import org.junit.Before;
import org.junit.Test;

import com.zsrt.day20170412.student.dao.StudentDao;
import com.zsrt.day20170412.student.entity.StudentEntity;
import com.zsrt.utils.ArrayUtil;

/**
 * @author jmj
 * @date 2017年4月12日
 * @time 下午12:22:32
 */
public class StudentTest {
	private StudentEntity[] students = new StudentEntity[5];
	private StudentDao dao = new StudentDao();
	private Scanner scanner ;
	@Before
	public void Before(){
		scanner = new Scanner(System.in);
		StudentEntity jmj=new StudentEntity();
		jmj.setName("贾梦菊");
		jmj.setScore(67);
		students[0]=jmj;
		StudentEntity zjy=new StudentEntity();
		zjy.setName("张嘉源");
		zjy.setScore(76);
		students[1]=zjy;
		StudentEntity lzh=new StudentEntity();
		lzh.setName("罗智壕");
		lzh.setScore(56);
		students[2]=lzh;
		StudentEntity hxq=new StudentEntity();
		hxq.setName("何小强");
		hxq.setScore(86);
		students[3]=hxq;
		StudentEntity jzh=new StudentEntity();
		jzh.setName("靳志辉");
		jzh.setScore(45);
		students[4]=jzh;
	}
	
	
	/**
	 * 打印不及格的人
	 * @throws Exception
	 */
	@Test
	public void findNGTest() throws Exception {
		
		StudentEntity[] jgs = dao.findNG(students);

		ArrayUtil.StudentEntity(jgs);
		
	}
	
	/**
	 * 改变数组中某个学生的分数
	 * @throws Exception
	 */
	@Test
	public void updateStudentScoreTest() throws Exception {
		StudentEntity student = new StudentEntity();
		
		//输入你想改变的学生的姓名
		System.out.println("请输入你想改变的学生姓名");
		String oldName = scanner.nextLine();
		//输入你想改变后的值
		System.out.println("请输入改变后的分数");
		double updateScore = scanner.nextDouble();
		student = dao.updateStudentScore(students, oldName, updateScore);
		System.out.println(student);
	}
	
	/**
	 * 添加一个学生信息
	 * @throws Exception
	 */
	@Test
	public void addStudentTest() throws Exception {
		dao.addStudent(students);
	}
	
	/**
	 * 删除单个信息
	 * @throws Exception
	 */
	@Test
	public void deleteStudentTest() throws Exception {
		System.out.println("请输入你想删除的学生姓名");
		String name =scanner.nextLine();
		StudentEntity[] newStudents=dao.deleteStudent(students, name );
		ArrayUtil.StudentEntity(newStudents);
	}
	
    /**
     * 执行删除操作 
     * 删除一批存在或不存在的学生
     * @throws Exception
     */
	@Test
	public void deleteSomeStudentsTest() throws Exception {
		
		
		 //String[] deleteStudents = {"贾梦菊","贾乃亮","张嘉源"};
		 StudentEntity[] deleteStudents = new StudentEntity[3];
		 StudentEntity zjy=new StudentEntity();
		 zjy.setName("张嘉源");
		 zjy.setScore(76);
		 StudentEntity lzh=new StudentEntity();
		 lzh.setName("罗智壕");
		 lzh.setScore(56);
		 StudentEntity lhh=new StudentEntity();
		 lhh.setName("林华华");
		 lhh.setScore(56);
		 
		 deleteStudents[0]=zjy;
		 deleteStudents[1] = lzh;
		 deleteStudents[2] = lhh;
		 
		 StudentEntity[] newStudents=dao.deleteSomeStudents(students,deleteStudents);
		 ArrayUtil.StudentEntity(newStudents);
		
	}
	
	

}
